package o;

import com.huawei.hms.framework.network.restclient.hwhttp.HttpContants;
import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsConfig;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

final class fwd {
    static final fwb[] ˋ = new fwb[]{new fwb(fwb.ʼ, ""), new fwb(fwb.ˊ, HttpContants.HTTP_METHOD_GET), new fwb(fwb.ˊ, "POST"), new fwb(fwb.ˎ, "/"), new fwb(fwb.ˎ, "/index.html"), new fwb(fwb.ˋ, "http"), new fwb(fwb.ˋ, "https"), new fwb(fwb.ˏ, "200"), new fwb(fwb.ˏ, "204"), new fwb(fwb.ˏ, "206"), new fwb(fwb.ˏ, "304"), new fwb(fwb.ˏ, "400"), new fwb(fwb.ˏ, "404"), new fwb(fwb.ˏ, "500"), new fwb("accept-charset", ""), new fwb("accept-encoding", "gzip, deflate"), new fwb("accept-language", ""), new fwb("accept-ranges", ""), new fwb("accept", ""), new fwb("access-control-allow-origin", ""), new fwb("age", ""), new fwb("allow", ""), new fwb("authorization", ""), new fwb("cache-control", ""), new fwb("content-disposition", ""), new fwb("content-encoding", ""), new fwb("content-language", ""), new fwb("content-length", ""), new fwb("content-location", ""), new fwb("content-range", ""), new fwb("content-type", ""), new fwb("cookie", ""), new fwb("date", ""), new fwb("etag", ""), new fwb("expect", ""), new fwb("expires", ""), new fwb("from", ""), new fwb("host", ""), new fwb("if-match", ""), new fwb("if-modified-since", ""), new fwb("if-none-match", ""), new fwb("if-range", ""), new fwb("if-unmodified-since", ""), new fwb("last-modified", ""), new fwb("link", ""), new fwb("location", ""), new fwb("max-forwards", ""), new fwb("proxy-authenticate", ""), new fwb("proxy-authorization", ""), new fwb("range", ""), new fwb("referer", ""), new fwb("refresh", ""), new fwb("retry-after", ""), new fwb("server", ""), new fwb("set-cookie", ""), new fwb("strict-transport-security", ""), new fwb("transfer-encoding", ""), new fwb("user-agent", ""), new fwb("vary", ""), new fwb("via", ""), new fwb("www-authenticate", "")};
    static final Map<fxh, Integer> ˎ = ˋ();

    static final class b {
        int ʻ;
        private boolean ʼ;
        private int ʽ;
        int ˊ;
        int ˋ;
        int ˎ;
        fwb[] ˏ;
        int ॱ;
        private final boolean ॱॱ;
        private final fxi ᐝ;

        b(fxi o_fxi) {
            this(4096, true, o_fxi);
        }

        b(int i, boolean z, fxi o_fxi) {
            this.ʽ = ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED;
            this.ˏ = new fwb[8];
            this.ˋ = this.ˏ.length - 1;
            this.ˎ = 0;
            this.ʻ = 0;
            this.ˊ = i;
            this.ॱ = i;
            this.ॱॱ = z;
            this.ᐝ = o_fxi;
        }

        private void ˋ() {
            Arrays.fill(this.ˏ, null);
            this.ˋ = this.ˏ.length - 1;
            this.ˎ = 0;
            this.ʻ = 0;
        }

        private int ˏ(int i) {
            int i2 = 0;
            if (i > 0) {
                for (int length = this.ˏ.length - 1; length >= this.ˋ && i > 0; length--) {
                    i -= this.ˏ[length].ʻ;
                    this.ʻ -= this.ˏ[length].ʻ;
                    this.ˎ--;
                    i2++;
                }
                System.arraycopy(this.ˏ, this.ˋ + 1, this.ˏ, (this.ˋ + 1) + i2, this.ˎ);
                Arrays.fill(this.ˏ, this.ˋ + 1, (this.ˋ + 1) + i2, null);
                this.ˋ += i2;
            }
            return i2;
        }

        private void ˎ(fwb o_fwb) {
            int i = o_fwb.ʻ;
            if (i > this.ॱ) {
                ˋ();
                return;
            }
            ˏ((this.ʻ + i) - this.ॱ);
            if (this.ˎ + 1 > this.ˏ.length) {
                Object obj = new fwb[(this.ˏ.length * 2)];
                System.arraycopy(this.ˏ, 0, obj, this.ˏ.length, this.ˏ.length);
                this.ˋ = this.ˏ.length - 1;
                this.ˏ = obj;
            }
            int i2 = this.ˋ;
            this.ˋ = i2 - 1;
            this.ˏ[i2] = o_fwb;
            this.ˎ++;
            this.ʻ = i + this.ʻ;
        }

        void ॱ(List<fwb> list) throws IOException {
            if (this.ʼ) {
                if (this.ʽ < this.ॱ) {
                    ˏ(this.ʽ, 31, 32);
                }
                this.ʼ = false;
                this.ʽ = ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED;
                ˏ(this.ॱ, 31, 32);
            }
            int size = list.size();
            for (int i = 0; i < size; i++) {
                int intValue;
                int i2;
                fwb o_fwb = (fwb) list.get(i);
                fxh ʻ = o_fwb.ॱॱ.ʻ();
                fxh o_fxh = o_fwb.ᐝ;
                Integer num = (Integer) fwd.ˎ.get(ʻ);
                if (num != null) {
                    intValue = num.intValue() + 1;
                    if (intValue > 1 && intValue < 8) {
                        if (fvg.ॱ(fwd.ˋ[intValue - 1].ᐝ, (Object) o_fxh)) {
                            i2 = intValue;
                        } else if (fvg.ॱ(fwd.ˋ[intValue].ᐝ, (Object) o_fxh)) {
                            i2 = intValue + 1;
                        }
                    }
                    i2 = -1;
                } else {
                    intValue = -1;
                    i2 = -1;
                }
                if (i2 == -1) {
                    int length = this.ˏ.length;
                    for (int i3 = this.ˋ + 1; i3 < length; i3++) {
                        if (fvg.ॱ(this.ˏ[i3].ॱॱ, (Object) ʻ)) {
                            if (fvg.ॱ(this.ˏ[i3].ᐝ, (Object) o_fxh)) {
                                i2 = (i3 - this.ˋ) + fwd.ˋ.length;
                                break;
                            } else if (intValue == -1) {
                                intValue = (i3 - this.ˋ) + fwd.ˋ.length;
                            }
                        }
                    }
                }
                if (i2 != -1) {
                    ˏ(i2, 127, DnsConfig.MAX_CACHE_ENTRIES);
                } else if (intValue == -1) {
                    this.ᐝ.ˊ(64);
                    ˏ(ʻ);
                    ˏ(o_fxh);
                    ˎ(o_fwb);
                } else if (!ʻ.ˋ(fwb.ॱ) || fwb.ʼ.equals(ʻ)) {
                    ˏ(intValue, 63, 64);
                    ˏ(o_fxh);
                    ˎ(o_fwb);
                } else {
                    ˏ(intValue, 15, 0);
                    ˏ(o_fxh);
                }
            }
        }

        void ˏ(int i, int i2, int i3) {
            if (i < i2) {
                this.ᐝ.ˊ(i3 | i);
                return;
            }
            this.ᐝ.ˊ(i3 | i2);
            int i4 = i - i2;
            while (i4 >= DnsConfig.MAX_CACHE_ENTRIES) {
                this.ᐝ.ˊ((i4 & 127) | DnsConfig.MAX_CACHE_ENTRIES);
                i4 >>>= 7;
            }
            this.ᐝ.ˊ(i4);
        }

        void ˏ(fxh o_fxh) throws IOException {
            if (!this.ॱॱ || fwp.ˋ().ॱ(o_fxh) >= o_fxh.ʼ()) {
                ˏ(o_fxh.ʼ(), 127, 0);
                this.ᐝ.ˎ(o_fxh);
                return;
            }
            Object o_fxi = new fxi();
            fwp.ˋ().ˋ(o_fxh, o_fxi);
            fxh ॱˎ = o_fxi.ॱˎ();
            ˏ(ॱˎ.ʼ(), 127, DnsConfig.MAX_CACHE_ENTRIES);
            this.ᐝ.ˎ(ॱˎ);
        }

        void ˊ(int i) {
            this.ˊ = i;
            int min = Math.min(i, 16384);
            if (this.ॱ != min) {
                if (min < this.ॱ) {
                    this.ʽ = Math.min(this.ʽ, min);
                }
                this.ʼ = true;
                this.ॱ = min;
                ॱ();
            }
        }

        private void ॱ() {
            if (this.ॱ >= this.ʻ) {
                return;
            }
            if (this.ॱ == 0) {
                ˋ();
            } else {
                ˏ(this.ʻ - this.ॱ);
            }
        }
    }

    static final class e {
        private final int ʽ;
        int ˊ;
        fwb[] ˋ;
        int ˎ;
        int ˏ;
        private final List<fwb> ॱ;
        private final fxg ॱॱ;
        private int ᐝ;

        e(int i, fxw o_fxw) {
            this(i, i, o_fxw);
        }

        e(int i, int i2, fxw o_fxw) {
            this.ॱ = new ArrayList();
            this.ˋ = new fwb[8];
            this.ˊ = this.ˋ.length - 1;
            this.ˏ = 0;
            this.ˎ = 0;
            this.ʽ = i;
            this.ᐝ = i2;
            this.ॱॱ = fxr.ˎ(o_fxw);
        }

        private void ˏ() {
            if (this.ᐝ >= this.ˎ) {
                return;
            }
            if (this.ᐝ == 0) {
                ˊ();
            } else {
                ˊ(this.ˎ - this.ᐝ);
            }
        }

        private void ˊ() {
            Arrays.fill(this.ˋ, null);
            this.ˊ = this.ˋ.length - 1;
            this.ˏ = 0;
            this.ˎ = 0;
        }

        private int ˊ(int i) {
            int i2 = 0;
            if (i > 0) {
                for (int length = this.ˋ.length - 1; length >= this.ˊ && i > 0; length--) {
                    i -= this.ˋ[length].ʻ;
                    this.ˎ -= this.ˋ[length].ʻ;
                    this.ˏ--;
                    i2++;
                }
                System.arraycopy(this.ˋ, this.ˊ + 1, this.ˋ, (this.ˊ + 1) + i2, this.ˏ);
                this.ˊ += i2;
            }
            return i2;
        }

        void ˎ() throws IOException {
            while (!this.ॱॱ.ᐝ()) {
                int ʻ = this.ॱॱ.ʻ() & 255;
                if (ʻ == DnsConfig.MAX_CACHE_ENTRIES) {
                    throw new IOException("index == 0");
                } else if ((ʻ & DnsConfig.MAX_CACHE_ENTRIES) == DnsConfig.MAX_CACHE_ENTRIES) {
                    ˋ(ˋ(ʻ, 127) - 1);
                } else if (ʻ == 64) {
                    ॱॱ();
                } else if ((ʻ & 64) == 64) {
                    ˏ(ˋ(ʻ, 63) - 1);
                } else if ((ʻ & 32) == 32) {
                    this.ᐝ = ˋ(ʻ, 31);
                    if (this.ᐝ < 0 || this.ᐝ > this.ʽ) {
                        throw new IOException("Invalid dynamic table size update " + this.ᐝ);
                    }
                    ˏ();
                } else if (ʻ == 16 || ʻ == 0) {
                    ʻ();
                } else {
                    ˎ(ˋ(ʻ, 15) - 1);
                }
            }
        }

        public List<fwb> ॱ() {
            List arrayList = new ArrayList(this.ॱ);
            this.ॱ.clear();
            return arrayList;
        }

        private void ˋ(int i) throws IOException {
            if (ᐝ(i)) {
                this.ॱ.add(fwd.ˋ[i]);
                return;
            }
            int ॱ = ॱ(i - fwd.ˋ.length);
            if (ॱ < 0 || ॱ >= this.ˋ.length) {
                throw new IOException("Header index too large " + (i + 1));
            }
            this.ॱ.add(this.ˋ[ॱ]);
        }

        private int ॱ(int i) {
            return (this.ˊ + 1) + i;
        }

        private void ˎ(int i) throws IOException {
            this.ॱ.add(new fwb(ʽ(i), ˋ()));
        }

        private void ʻ() throws IOException {
            this.ॱ.add(new fwb(fwd.ˋ(ˋ()), ˋ()));
        }

        private void ˏ(int i) throws IOException {
            ˎ(-1, new fwb(ʽ(i), ˋ()));
        }

        private void ॱॱ() throws IOException {
            ˎ(-1, new fwb(fwd.ˋ(ˋ()), ˋ()));
        }

        private fxh ʽ(int i) throws IOException {
            if (ᐝ(i)) {
                return fwd.ˋ[i].ॱॱ;
            }
            int ॱ = ॱ(i - fwd.ˋ.length);
            if (ॱ >= 0 && ॱ < this.ˋ.length) {
                return this.ˋ[ॱ].ॱॱ;
            }
            throw new IOException("Header index too large " + (i + 1));
        }

        private boolean ᐝ(int i) {
            return i >= 0 && i <= fwd.ˋ.length - 1;
        }

        private void ˎ(int i, fwb o_fwb) {
            this.ॱ.add(o_fwb);
            int i2 = o_fwb.ʻ;
            if (i != -1) {
                i2 -= this.ˋ[ॱ(i)].ʻ;
            }
            if (i2 > this.ᐝ) {
                ˊ();
                return;
            }
            int ˊ = ˊ((this.ˎ + i2) - this.ᐝ);
            if (i == -1) {
                if (this.ˏ + 1 > this.ˋ.length) {
                    Object obj = new fwb[(this.ˋ.length * 2)];
                    System.arraycopy(this.ˋ, 0, obj, this.ˋ.length, this.ˋ.length);
                    this.ˊ = this.ˋ.length - 1;
                    this.ˋ = obj;
                }
                ˊ = this.ˊ;
                this.ˊ = ˊ - 1;
                this.ˋ[ˊ] = o_fwb;
                this.ˏ++;
            } else {
                this.ˋ[(ˊ + ॱ(i)) + i] = o_fwb;
            }
            this.ˎ = i2 + this.ˎ;
        }

        private int ᐝ() throws IOException {
            return this.ॱॱ.ʻ() & 255;
        }

        int ˋ(int i, int i2) throws IOException {
            int i3 = i & i2;
            if (i3 < i2) {
                return i3;
            }
            i3 = 0;
            while (true) {
                int ᐝ = ᐝ();
                if ((ᐝ & DnsConfig.MAX_CACHE_ENTRIES) == 0) {
                    return (ᐝ << i3) + i2;
                }
                i2 += (ᐝ & 127) << i3;
                i3 += 7;
            }
        }

        fxh ˋ() throws IOException {
            int ᐝ = ᐝ();
            Object obj = (ᐝ & DnsConfig.MAX_CACHE_ENTRIES) == DnsConfig.MAX_CACHE_ENTRIES ? 1 : null;
            ᐝ = ˋ(ᐝ, 127);
            if (obj != null) {
                return fxh.ˎ(fwp.ˋ().ˋ(this.ॱॱ.ॱॱ((long) ᐝ)));
            }
            return this.ॱॱ.ˋ((long) ᐝ);
        }
    }

    private static Map<fxh, Integer> ˋ() {
        Map linkedHashMap = new LinkedHashMap(ˋ.length);
        for (int i = 0; i < ˋ.length; i++) {
            if (!linkedHashMap.containsKey(ˋ[i].ॱॱ)) {
                linkedHashMap.put(ˋ[i].ॱॱ, Integer.valueOf(i));
            }
        }
        return Collections.unmodifiableMap(linkedHashMap);
    }

    static fxh ˋ(fxh o_fxh) throws IOException {
        int i = 0;
        int ʼ = o_fxh.ʼ();
        while (i < ʼ) {
            byte ˏ = o_fxh.ˏ(i);
            if (ˏ < (byte) 65 || ˏ > (byte) 90) {
                i++;
            } else {
                throw new IOException("PROTOCOL_ERROR response malformed: mixed case name: " + o_fxh.ˊ());
            }
        }
        return o_fxh;
    }
}
